import numpy as np
import matplotlib.pyplot as plt
from matplotlib import colors

if __name__ == '__main__':
    cluser_file = open("output/cluster-centers")
    clusers = []
    for line in cluser_file:
        line = line.strip().split(",")
        clusers.append([int(line[0]), (float(line[2]), float(line[3]))])
    type_num = len(clusers)
    points_file = open("output/cluster-points")
    points = []
    for line in points_file:
        line = line.replace('\t', ',').strip().split(",")
        points.append([int(line[2]), (float(line[0]), float(line[1]))])

    rng = np.random.RandomState(0)
    color = []
    for i in range(len(clusers)):
        step = 1 / len(clusers)
        color.append((i + 1) * step)

    changecolor = colors.Normalize(vmin=0.0, vmax=1.0)
    for i in range(len(points)):
        markIndex = points[i][0]
        plt.scatter(points[i][1][0], points[i][1][1], s=20, c=color[markIndex], marker="o", cmap='brg',
                    norm=changecolor)
    for i in range(type_num):
        markIndex = clusers[i][0]
        plt.scatter(clusers[i][1][0], clusers[i][1][1], s=150, c=color[markIndex], marker="*", cmap='brg',
                    norm=changecolor)
    plt.title('K-Means Result K='+str(type_num))
    plt.xlabel("x")
    plt.ylabel("y")


    plt.show()
